package com.mflex.WHSmartWhouseAd.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mflex.WHSmartWhouseAd.R;
import com.mflex.WHSmartWhouseAd.model.TransTaskInfo;
import com.xuexiang.xutil.common.StringUtils;

import java.util.List;

public class OutShelfDetailAdapter extends BaseAdapter {
    List<TransTaskInfo> items;
    Activity context;
    private SparseBooleanArray itemChecked = new SparseBooleanArray();

    public OutShelfDetailAdapter(Activity context, List<TransTaskInfo> items) {
        this.context = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TransTaskInfo item = items.get(position);
        View view = convertView;
        view = context.getLayoutInflater().inflate(R.layout.item_out_shelf_detail_list, null);
        ((TextView) view.findViewById(R.id.txtTasknum)).setText(item.getTaskName());
        ((TextView) view.findViewById(R.id.txtStatus)).setText(item.getStaus());

        CheckBox checkBox= (CheckBox) view.findViewById(R.id.cB);


//        String itemText = getItem(position).toString();
//        checkBox.setText(itemText);
        View finalView = view;
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(checkBox.isChecked()){
                  item.setCheckbox(true);
//                    convertView.setBackgroundColor(Color.GREEN);
                    finalView.findViewById(R.id.txtList).setBackgroundColor(Color.GREEN);
                }
                else
                {
                   item.setCheckbox(false);
//                    convertView.setBackgroundColor(Color.TRANSPARENT);
                    finalView.findViewById(R.id.txtList).setBackgroundColor(Color.TRANSPARENT);
                }
            }
        });

//        if (StringUtils.equals("1",item.getflag())) {
//            item.setCheckbox(true);
//            ((LinearLayout) view.findViewById(R.id.txtList)).setBackgroundColor(Color.GREEN);
//        }
//        else {item.setCheckbox(false);}

        return view;
    }
}